package com.k.comnote.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.k.comnote.R;
import com.k.comnote.model.ItemDrawer;

import java.util.List;

/**
 * Created by K on 2015/8/17.
 */
public class MyAdapterForDrawer extends BaseAdapter {

    private List<ItemDrawer> mList;
    private LayoutInflater mInflater;

    public MyAdapterForDrawer(Context context, List<ItemDrawer> list) {
        this.mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.itembean, null);
            viewHolder.listIcon = (ImageView) convertView.findViewById(R.id.list_icon);
            viewHolder.listMenu = (TextView) convertView.findViewById(R.id.list_menu);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ItemDrawer bean = mList.get(position);
        viewHolder.listIcon.setImageResource(bean.itemImageResId);
        viewHolder.listMenu.setText(bean.listMenu);

        return convertView;
    }

    class ViewHolder {
        private ImageView listIcon;
        private TextView listMenu;
    }
}
